﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace JCSelector
{

    // Copyright(c) 2010 Raymond L. Brady
    // Please read the copyright that has been included with this project before modifying or distributing this program.
    //
    [System.ComponentModel.DefaultBindingProperty("Text")]
    public partial class JCTouchSelector : UserControl
    {

    private ItemSelectionForm JCItemsForm = new ItemSelectionForm();
    private List<string> mItems = new List<string>();

    public JCTouchSelector()
    {
        InitializeComponent();
        this.JCItemsForm.Selected += new JCSelectedItemHandler(this.JCSelectionChanged);
    }

    #region "Public Properties"
        [Category("JC Touch Selector")]
        [Description("Gets or sets the title for the control.")]
        public string JCControlTitleText
        {
            get { return this.TitleLabel1.Text; }
            set { this.TitleLabel1.Text = value; }
        }


        [Category("JC Touch Selector")]
        [Description("Gets or sets the opacity percentage for the item list.")]
        public double ItemList_Opacity
        {
            get { return this.JCItemsForm.Opacity; }
            set { this.JCItemsForm.Opacity = value; }
        }


        [Category("JC Touch Selector")]
        [Description("Indicates the list that this control will get it's items.")]
        public List<string> Items
        {
            get { return this.mItems; }
            set {
                    this.mItems = value;
                    this.JCItemsForm.JCItems = this.mItems;
                }
        }

        [Category("JC Touch Selector")]
        [Description("Default binding property of the control.")]
        [Bindable(true,BindingDirection.TwoWay)]
        public override string Text
        {
            get { return this.JCItemLabel.Text; }
            set { this.JCItemLabel.Text = value; }
        }

        [Category("JC Touch Selector")]
        [Description("Gets ot sets the BackColor of the item list.")]
        public Color ItemList_BackColor
        {
            get { return this.JCItemsForm.BackColor; }
            set { this.JCItemsForm.BackColor = value; }
        }
        [Category("JC Touch Selector")]
        [Description("Gets or sets the font used for item buttons.")]
        public virtual Font Button_Font
        {
            get { return this.JCItemsForm.Button_Font; }
            set { this.JCItemsForm.Button_Font = value; }
        }
    #endregion

    #region "Event Code"
        private void JCSelectionChanged(object sender, EventArgs e, string JCItem)
        {
            this.JCItemLabel.Text = JCItem;
            this.OnValidating(new CancelEventArgs());
        }

        private void JCTouchSelector_Validating(object sender, CancelEventArgs e)
        {
            OnTextChanged(new System.EventArgs());
        }    
    
    #endregion

    #region "Click Code"
        private void TouchButton_Click(object sender, EventArgs e)
        {
            JCItemsForm.ShowDialog(this);
        }
    #endregion




    }
}
